﻿using Max.PH5_2008A.ShoppingCode.Domain;
using Max.PH5_2008A.ShoppingCode.IService;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace Max.PH5_2008A.ShoppingCode.API.Controllers
{
    [Route("member/info")]
    [ApiController]
    public class MemberInfoController : BaseController<MemeberInfoEntity>
    {
        IMemberInfoService _service;
        public MemberInfoController(IMemberInfoService service) : base(service)
        {
            _service = service;
        }


        [HttpPost]
        public override IActionResult Insert(MemeberInfoEntity t)
        {
            t.Password = MD5Hash.Hash.Content(t.Password);
            _service.Insert(t);
            
            return Ok("注册成功");
        }

        [HttpPost("login")]
        public IActionResult Login(MemeberInfoEntity model)
        {
            model.Password = MD5Hash.Hash.Content(model.Password);

            var result = _service.Login(model.Phone, model.Password);

            return Ok(new { statue = result.Item1, msg = result.Item2, data = result.Item3 });
        }
    }
}
